package org.webball.server;

import org.webball.base.interfaces.ICommunication;
/**
 * Representation of connected user, used on server side.
 * Class holds reference to communication, each User is working on
 * diffrent thread
 * @author Marcin Kaczor
 *
 */
public class User {
	private ICommunication communication;
	private String name= "";
	boolean ready= false;
	/**
	 * Creates new User with Communication thread,
	 * also starts new Communicator thread
	 * @param communication
	 */
	public User(ICommunication communication){
		this.communication= communication;
		Message message= new Message();
		communication.setMessage(message);
		Communicator communicator= new Communicator(this, message);
		communicator.start();
	}
	/**
	 * sets User name
	 * @param name
	 */
	public void setName(String name){
		this.name= name;
	}
	
	public String getName() {
		return name;
	}
	/**
	 * sends object to this user
	 * @param object
	 */
	public void send(Object object){
		communication.send(object);
	}
	/**
	 * set flag read, it means that player is ready to play
	 */
	public void setReady(){
		ready= true;
	}
	/**
	 * ends communication thread and connection with user
	 */
	public void endConnection(){
		communication.end();
	}
}
